package net.realsee.controller.system;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import net.realsee.common.config.AppConfig;
import net.realsee.common.utils.StringUtils;
import net.realsee.framework.core.domain.R;
import net.realsee.service.system.ISysConfigService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * 首页
 *
 * @author realsee
 */
@RequiredArgsConstructor
@RestController
public class SysIndexController {

    /**
     * 系统基础配置
     */
    private final AppConfig appConfig;

    private final ISysConfigService configService;

    /**
     * 访问首页，提示语
     */
    @SaIgnore
    @GetMapping("/")
    public String index() {
        return StringUtils.format("欢迎使用{}后台管理框架，当前版本：v{}，请通过前端地址访问。", appConfig.getName(), appConfig.getVersion());
    }


    /**
     * 查询首页背景图url
     */
    @SaIgnore
    @GetMapping(value = "/index/backgroundImg")
    public R<Void> getIndexBackgroundImg() {
        return R.ok(configService.selectIndexBackgroundImgByConfigKey());
    }

    /**
     * 根据参数键名查询参数值
     */
    @SaIgnore
    @GetMapping(value = "/index/{configKey}")
    public R<Void> getIndexInfo(@PathVariable String configKey) {
        return R.ok(configService.selectConfigByKey(configKey));
    }

}
